import { http } from '@/utils/http'

/** 查询角色列表 */
export const listRole = (params?: object) => {
  return http.request<HttpPaginationResponse<Array<any>>>('get', '/system/role/list', {
    params,
  })
}

/** 查询角色详细 */
export const getRole = (roleId: number) => {
  return http.request<HttpResponse<Object>>('get', '/system/role/' + roleId)
}

/** 新增角色 */
export const addRole = (data?: object) => {
  return http.request<HttpResponse<Object>>('post', '/system/role', {
    data,
  })
}

/** 修改角色 */
export const updateRole = (data?: object) => {
  return http.request<HttpResponse<Object>>('put', '/system/role', {
    data,
  })
}

/** 角色数据权限 */
export const dataScope = (data?: object) => {
  return http.request<HttpResponse<Object>>('put', '/system/role/dataScope', {
    data,
  })
}

/** 角色状态修改 */
export const changeRoleStatus = (roleId: string, status: string) => {
  const data = {
    roleId,
    status,
  }
  return http.request<HttpResponse<Object>>('put', '/system/role/changeStatus', {
    data,
  })
}

/** 删除角色 */
export const delRole = (roleId?: string) => {
  return http.request<HttpResponse<Object>>('delete', '/system/role/' + roleId)
}

/** 查询角色已授权用户列表 */
export const allocatedUserList = (params?: object) => {
  return http.request<HttpPaginationResponse<Array<any>>>(
    'get',
    '/system/role/authUser/allocatedList',
    { params }
  )
}

/** 查询角色未授权用户列表 */
export const unallocatedUserList = (params?: object) => {
  return http.request<HttpPaginationResponse<Array<any>>>(
    'get',
    '/system/role/authUser/unallocatedList',
    { params }
  )
}

/** 取消用户授权角色 */
export const authUserCancel = (data?: object) => {
  return http.request<HttpResponse<Object>>('put', '/system/role/authUser/cancel', {
    data,
  })
}

/** 批量取消用户授权角色 */
export const authUserCancelAll = (data?: object) => {
  return http.request<HttpResponse<Object>>('put', '/system/role/authUser/cancelAll', {
    data,
  })
}

/** 授权用户选择 */
export const authUserSelectAll = (params?: object) => {
  return http.request<HttpResponse<Object>>('put', '/system/role/authUser/selectAll', {
    params,
  })
}

/** 根据角色ID查询部门树结构 */
export const deptTreeSelect = (roleId: string) => {
  return http.request<HttpResponse<Object>>('get', '/system/role/deptTree/' + roleId)
}
